<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib uri="/authtaglib" prefix="auth" %>
<!DOCTYPE html>
<html>
<head>
<title>人员级别</title>
<jsp:include page="/include.jsp"/>
<script type="text/javascript">
//新增数据源配置信息窗口
function doAddDatasource() {
    $('<div id="addDiv"/>').dialog({
        href: '${pageContext.request.contextPath}/cnbdw/levelAction!toAddPage.action',
        top: 10,
        width: 300,
        modal: true,
        title: '新增级别',
        buttons: [
            {
                id: 'btnSave',
                text: '保存',
                iconCls: '',
                handler: function () {
                    var d = $(this).closest('.window-body');
                    $('#form').form('submit', {
                        url: '${pageContext.request.contextPath}/cnbdw/levelAction!add.action',
                        onSubmit: function () {
                            if ($(this).form("validate")) {
                                $.messager.progress({title: '提示', text: '正在保存，请稍候 ....'});
                            } else {
                                return false;
                            }
                        },
                        success: function (result) {
                            try {
                                var r = $.parseJSON(result);
                                if (r.returnFlag) {
                                    $('#datagrid').datagrid('reload');
                                    d.dialog('destroy');
                                }
                                //显示提示信息
                                $.messager.show({
                                    title: '提示',
                                    msg: r.returnMsg
                                });
                            } catch (e) {
                            }
                            $.messager.progress('close');
                        }
                    });
                }
            },
            {
                id: 'btnCancle',
                text: '取消',
                iconCls: '',
                handler: function () {
                    $(this).closest('.window-body').dialog('destroy');
                }
            }
        ],
        onClose: function () {
            $(this).dialog('destroy');
            //刷新主列表
            $('#datagrid').datagrid('reload');
        }
    });
}
//修改数据源配置信息窗口
function doEditDatasource(id) {
    $('<div id="addDiv"/>').dialog({
        href: '${pageContext.request.contextPath}/cnbdw/levelAction!toEditPage.action?id=' + id,
        top: 10,
        width: 300,
        modal: true,
        title: '修改级别',
        buttons: [
            {
                id: 'btnSave',
                text: '保存',
                iconCls: '',
                handler: function () {
                    var d = $(this).closest('.window-body');
                    $('#form').form('submit', {
                        url: '${pageContext.request.contextPath}/cnbdw/levelAction!update.action',
                        onSubmit: function () {
                            if ($(this).form("validate")) {
                                $.messager.progress({title: '提示', text: '正在保存，请稍候 ....'});
                            } else {
                                return false;
                            }
                        },
                        success: function (result) {
                            try {
                                var r = $.parseJSON(result);
                                if (r.returnFlag) {
                                    $('#datagrid').datagrid('reload');
                                    d.dialog('destroy');
                                }
                                //显示提示信息
                                $.messager.show({
                                    title: '提示',
                                    msg: r.returnMsg
                                });
                            } catch (e) {
                            }
                            $.messager.progress('close');
                        }
                    });
                }
            },
            {
                id: 'btnCancle',
                text: '取消',
                iconCls: '',
                handler: function () {
                    $(this).closest('.window-body').dialog('destroy');
                }
            }
        ],
        onClose: function () {
            $(this).dialog('destroy');
            //刷新主列表
            $('#datagrid').datagrid('reload');
        }
    });
}
//删除
function doDeleteDatasource(ids) {
    window.top.$.messager.confirm('提示', '是否确定删除该条记录？', function (b) {
        if (b) {
            $.ajax({
                url: '${pageContext.request.contextPath}/cnbdw/levelAction!delete.action',
                dataType: 'json',
                data: {ids: ids},
                success: function (data) {
                    $.messager.show({title: '提示', msg: data.returnMsg});
                    if (data.returnFlag) {
                        //刷新主列表
                        $('#datagrid').datagrid('reload');
                    }
                }
            });

        }
    });
}

//批量删除
function doBatchDelete() {
    var rows = $('#datagrid').datagrid('getChecked')
    if (rows.length <= 0) {
        $.messager.alert('提示', '没有选择任何记录');
    } else {
        var itemIds = [];
        $.each(rows, function (i, item) {
            itemIds.push(item.id);
        });
        $.messager.confirm('删除确认', '是否确定删除选中记录？', function (r) {
            if (r) {
                $.ajax({
                    url: '${pageContext.request.contextPath}/cnbdw/levelAction!delete.action',
                    async: false,
                    data: {ids: itemIds.join(",")},
                    dataType: "json",
                    success: function (result) {
                        $.messager.show({title: '提示', msg: result.returnMsg});
                        if (result.returnFlag) {
                            //刷新主列表
                            $('#datagrid').datagrid('reload');
                        }
                    }
                });
            }
        });
    }
}

//执行查询
function doQuery() {
    if ($("#datasource_query_form").form("validate")) {
        $("#datagrid").datagrid('options').queryParams = serializeObject($('#datasource_query_form')); //把查询条件赋值给datagrid内部变量
        $("#datagrid").datagrid('load'); //重新加载
    }
}
//重置查询条件
function doReset() {
    $('#datasource_query_form').form('reset');
}
//页面加载完后响应 onReady
$(function () {
    //查询按纽绑定事件
    $('#btnQuery').bind('click', doQuery);
    //重置按纽绑定事件
    $('#btnReset').bind('click', doReset);
    //初始化主列表
    $('#datagrid').datagrid({
        url: '${pageContext.request.contextPath}/cnbdw/levelAction!getAllDatasourceList.action',
        fit: true,
        border: false,
        fitColumns: true,
        pagination: true,
        pageList: [30],
        rownumbers: false,
        sortName: 'id',
        sortOrder: 'desc',
        striped: true,
        columns: [
            [
				{field: 'id', checkbox: true},
                {field: 'name', title: '级别名称', align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} return value;}},
                {field: 'level', title: '级别值', align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} return value;}},
                {field: 'createTime', title: '创建时间', align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} return value;}},
                {field: 'createUser', title: '创建人员', align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} return value;}},
                {field: 'updateTime', title: '修改时间', align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} return value;}},
                {field: 'updateUser', title: '修改人员', align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} return value;}},
                {field: 'action', title: '人员操作', align: 'right',
                    formatter: function (value, row, index) {
                        var html = "";
                        <auth:button authUrl="cnbdw/levelAction!update.action">
                        html += '<span  style="cursor:pointer" onclick="doEditDatasource(\'' + row.id + '\')"><img  src="${pageContext.request.contextPath}/images/icons/modify_or_edit.png" title="修改" alt="修改"/>修改&nbsp;&nbsp;</span>';
                        </auth:button>
                        <auth:button authUrl="cnbdw/levelAction!delete.action">
                        html += '<span style="cursor:pointer" onclick="doDeleteDatasource(\'' + row.id + '\')"><img src="${pageContext.request.contextPath}/images/icons/delete.png" title="删除" alt="删除" style="margin-top:2px;">删除&nbsp;&nbsp;</span>';
                        </auth:button>
                        return html;
                    }
                }
            ]
        ],
        toolbar: '#datagrid_toobar'
    });
});

function showFileUpload(callbackId) {
    window.top.$('<div/>').dialog({
        href: '${pageContext.request.contextPath}/cnbdw/special/file_upload.jsp',
        modal: true,
        top: ($(window.top).height() - 400) * 0.5,
        left: ($(window.top).width() - 600) * 0.5,
        width: 400,
        title: '上传附件',
        buttons: [
            {
                text: '保存',
                iconCls: '',
                id: 'fileUploadDialog',
                handler: function () {
                    //获取专题性别参数
                    var d = window.top.$(this).closest('.window-body');
                    if (window.top.fileValidateData()) {
                        window.top.$('#fileUploadForm').form('submit', {
                            url: '${pageContext.request.contextPath}/fileUploadAction!uploadFile.action',
                            success: function (result) {
                                try {
                                    var r = $.parseJSON(result);
                                    if (r.err != null && r.err != '') {
                                        //显示提示信息
                                        $.messager.show({
                                            title: '提示',
                                            msg: r.err
                                        });
                                    } else {
                                        $('#' + callbackId).val(r.msg);
                                        //关闭新增窗口
                                        d.dialog('destroy');
                                    }
                                } catch (e) {
                                    $.messager.alert('提示', result);
                                }
                            }
                        });
                    }
                }
            }
        ],
        onClose: function () {
            window.top.$(this).dialog('destroy');
        }
    });
}


function regionRelation(){
	var myid = "";
	var rows = $('#datagrid').datagrid('getChecked')
    if (rows.length <= 0) {
        $.messager.alert('提示', '没有选择任何记录');
        return;
    }else if(rows.length >1){
        $.messager.alert('提示', '只能选择一条记录');
        return;
    }else{
        $.each(rows, function (i, item) {
            myid = item.id;
        });
    }
	$('<div/>').dialog({
        href: '${pageContext.request.contextPath}/cnbdw/regionInfo/select-content.jsp?levelId=' + myid,
        modal: true,
        top: 0,
        left: ($(window.top).width() - 600) * 0.5,
        width: 700,
        title: '选择报警级别',
        buttons: [
            {
                text: '保存',
                iconCls: '',
                id: 'fileUploadDialog',
                handler: function () {
                	var d = $(this).closest('.window-body');
                    var datagrid = $('#datagrid_regioninfo2').datagrid("getData");
                    var myids = [];
                    $.each(datagrid.rows, function (index, item) {
                    	myids.push(item.id);
                    });
                    if(myids.length>0){
                    	$.ajax({
                            url: '${pageContext.request.contextPath}/cnbdw/levelAction!regionRelation.action',
                            async: false,
                            data: {id : myid,ids: myids.join(",")},
                            dataType: "json",
                            success: function (result) {
                                $.messager.show({title: '提示', msg: result.returnMsg});
                                if (result.returnFlag) {
                                    //刷新主列表
                                    $('#datagrid').datagrid('reload');
                                }
                            }
                        });
                    }else{
                    	$.messager.alert('提示', "没有选择信息");
                    }
                    d.dialog('destroy');
                }
            }
        ],
        onClose: function () {
            $(this).dialog('destroy');
        }
    });
}

function roomTypeRelation(){
	var myid = "";
	var rows = $('#datagrid').datagrid('getChecked')
    if (rows.length <= 0) {
        $.messager.alert('提示', '没有选择任何记录');
        return;
    }else if(rows.length >1){
        $.messager.alert('提示', '只能选择一条记录');
        return;
    }else{
        $.each(rows, function (i, item) {
            myid = item.id;
        });
    }
	$('<div/>').dialog({
        href: '${pageContext.request.contextPath}/cnbdw/roomType/select-content.jsp?levelId=' + myid,
        modal: true,
        top: 0,
        left: ($(window.top).width() - 600) * 0.5,
        width: 700,
        title: '选择类别',
        buttons: [
            {
                text: '保存',
                iconCls: '',
                id: 'fileUploadDialog',
                handler: function () {
                	var d = $(this).closest('.window-body');
                    var datagrid = $('#datagrid_roomtype2').datagrid("getData");
                    var myids = [];
                    $.each(datagrid.rows, function (index, item) {
                        myids.push(item.id);
                    });
                    if(myids.length>0){
                    	$.ajax({
                            url: '${pageContext.request.contextPath}/cnbdw/levelAction!roomTypeRelation.action',
                            async: false,
                            data: {id : myid,ids: myids.join(",")},
                            dataType: "json",
                            success: function (result) {
                                $.messager.show({title: '提示', msg: result.returnMsg});
                                if (result.returnFlag) {
                                    //刷新主列表
                                    $('#datagrid').datagrid('reload');
                                }
                            }
                        });
                    }else{
                    	$.messager.alert('提示', "没有选择信息");
                    }
                    d.dialog('destroy');
                }
            }
        ],
        onClose: function () {
            $(this).dialog('destroy');
        }
    });
}
</script>
</head>
<body class="easyui-layout">
<form id="datasource_query_form" method="post">
    <div data-options="region:'north'" style="height:80px;border-bottom:none;border-top:none;">
        <table border="0" cellpadding="0" cellspacing="0" height="100%" width="50%">
            <tr>
                <td style="width:0.1%;text-align:left;" nowrap="nowrap">
                    <label for="datasource_datsourcename">级别名称：</label>
                </td>
                <td style="width:1%;text-align:left;" nowrap="nowrap">
                    <input type="text" id="datasource_datsourcename" name="name" class="easyui-validatebox"
                           data-options="validType:'specialCharFilter'"/>
                </td>
                <td colspan="2" style="width:10%;text-align:left;" nowrap="nowrap">
                    <input type="button" id="btnQuery" value="查 询" class="search_btn"/>
                    <input type="button" id="btnReset" value="重 置" class="reset_btn"/>
                </td>
            </tr>
        </table>
    </div>
    <div data-options="region:'center'" style="border-top:none">
        <table id="datagrid"></table>
        <div id="datagrid_toobar" class="etl_panel_title">
            <auth:button authUrl="cnbdw/levelAction!add.action">
                <a href="javascript:void(0);" onclick="doAddDatasource()" class="easyui-linkbutton"
                   data-options="iconCls:'icon-add',plain:true" style="float:left;">新增</a>
            </auth:button>
            <div class="datagrid-btn-separator"></div>
            <auth:button authUrl="cnbdw/levelAction!delete.action">
                <a href="javascript:void(0);" onclick="doBatchDelete()" class="easyui-linkbutton"
                   data-options="iconCls:'icon-remove',plain:true" style="float:left;">批量删除</a>
            </auth:button>
            <!--  
            <div class="datagrid-btn-separator"></div>
            <auth:button authUrl="cnbdw/levelRoomAction!add.action">
                <a href="javascript:void(0);" onclick="regionRelation()" class="easyui-linkbutton"
                   data-options="iconCls:'deploy',plain:true" style="float:left;">与报警级别关联</a>
            </auth:button>
            <div class="datagrid-btn-separator"></div>
            <auth:button authUrl="cnbdw/levelRoomAction!add.action">
                <a href="javascript:void(0);" onclick="roomTypeRelation()" class="easyui-linkbutton"
                   data-options="iconCls:'deploy',plain:true">与住仓类别关联</a>
            </auth:button>-->
        </div>
    </div>
</form>
</body>
</html>

